/*
 ============================================================================
 Name		: DownloadInfoData.cpp
 Author	  : JohnLZeng
 Version	 : 1.0
 Copyright   : Your copyright notice
 Description : CDownloadInfoData implementation
 ============================================================================
 */

#include "DownloadInfoData.h"
#include "MacroUtil.h"

CDownloadInfoData::CDownloadInfoData()
:iUrl(NULL),iFile(NULL),iUpdate(ETrue),iRange(0),iState(EDownloadStateStop),
iDelete(EFalse)
	{
	// No implementation required
	}

CDownloadInfoData::~CDownloadInfoData()
	{
	SAFE_DELETE(iUrl)
	SAFE_DELETE(iFile)
	}

CDownloadInfoData* CDownloadInfoData::NewLC()
	{
	CDownloadInfoData* self = new (ELeave) CDownloadInfoData();
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
	}

CDownloadInfoData* CDownloadInfoData::NewL()
	{
	CDownloadInfoData* self = CDownloadInfoData::NewLC();
	CleanupStack::Pop(); // self;
	return self;
	}

void CDownloadInfoData::ConstructL()
	{

	}

void CDownloadInfoData::SetUrl(const TDesC& aUrl)
	{
	SAFE_DELETE(iUrl)
	SAFE_DELETE(iFile)
	
	iUrl = aUrl.AllocL();
	TInt pos = aUrl.LocateReverse('/');
	iFile = aUrl.Mid(pos+1).AllocL();
	}

CQWString CDownloadInfoData::GetUrlQ()
	{
	CQWString title;
	if (iUrl)
		{
		TPtrC ptr = iUrl->Des();
		TInt start = ptr.LocateReverse('/');
		TInt end = ptr.LocateReverse('.');
		ptr.Set(ptr.Mid(start+1,end-start-1));
		title.SetData((LPCWSTR)(ptr.Ptr()),ptr.Length());
		}
	return title;
	}

void CDownloadInfoData::SetFile(const TDesC& aFile)
	{
	SAFE_DELETE(iFile)
	
	iFile = aFile.AllocL();
	}
